package core;

import core.auxiliar.TypeEnum;
import core.generator.Skeletons;


public class SemanticExpressionNode {
	
	private TypeEnum lexemeType;
	private Object value;
	private Integer line;
	private String name;
	private Integer column;

	public SemanticExpressionNode(Integer line, Integer column, TypeEnum lexemeType, Object value) {
		this.lexemeType = lexemeType;
		this.value = value;
		this.line = line;
		this.column = column;
		this.name = null;
	}

	public Object getValue() {
		return this.value;
	}

	public void setValue(Object value) {
		this.value = value;
	}
	
	public Integer getLine() {
		return this.line;
	}

	public TypeEnum getType() {
		return this.lexemeType;
	}

	public void setLine(Integer line) {
		this.line = line;
	}

	public Integer getColumn() {
		return column;
	}

	public void setColumn(Integer column) {
		this.column = column;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public String toString() {
		
		String result = "Tipo não pode ser convertido em String";
		
		if (this.getName() != null) return this.getName();
		
		if (this.getType().equals(TypeEnum.INTEGER)){
			result = String.valueOf((Integer) this.getValue());
		} else if (this.getType().equals(TypeEnum.LONGINT)){
			result = String.valueOf((Long) this.getValue());
		} else if (this.getType().equals(TypeEnum.REAL)){
			result = String.valueOf((Double) this.getValue()); //<- Era pra ser (Float) no cast...
		} else if (this.getType().equals(TypeEnum.LONGREAL)){
			result = String.valueOf((Double) this.getValue());
		} else if (this.getType().equals(TypeEnum.STRING)){
			result = (String) this.getValue();
		} else if (this.getType().equals(TypeEnum.ARRAY)){
			result = "Arr("+Skeletons.getInstance().getLine()+")";
		}
		
		return result;
	}
}